import {Component, Input, OnInit} from '@angular/core';
import {CommonService} from "../../service/base/common.service";
import {NzModalService} from "ng-zorro-antd/modal";
import {AdminListHttpService} from "../../service/http/admin.list.http.service";
import {HttpCustomConfig} from "../../service/base/base.http.service";
import { NzMessageService } from 'ng-zorro-antd/message';
@Component({
  selector: 'app-admin-detail',
  templateUrl: './admin-detail.component.html',
  styleUrls: ['./admin-detail.component.less']
})


export class AdminDetailComponent implements OnInit {
  adminName:string='';
  account:string='';
  authType: string = '0';
  pwd:string=''
  adminAuthTypeArr = [
    { label: '企划管理员', value: '30', checked: false },
    { label: '运营管理员', value: '40', checked: false },
    { label: '财务管理员', value: '50', checked: false },
    { label: '超级管理员', value: '60', checked: false }
  ];
  adminAuthType:any[]=[]
  dataList: any[] = [];

  @Input()
  data: any;

  constructor(private commonService: CommonService,
              private modalService: NzModalService,
              private adminListHttpService: AdminListHttpService,
              private message: NzMessageService) {
  }

  defaultHttpConfig: HttpCustomConfig = {showLoading: false}

  ngOnInit(): void {
  }

  changeAdminAuthType(){
    this.adminAuthType = this.adminAuthTypeArr.filter(sub => sub.checked).map(sub=>sub.value)
  }
  checkSimplePhoneNum(value:any) {
    return /^1[0-9]{10}$/.test(value)
  }

  handleConfirm(){
    if (this.account==='' || this.adminName === '' || this.pwd === '') {
      this.message.create('error', `请填写所有信息`);
      return false
    }
    if (!this.checkSimplePhoneNum(this.account)) {
      this.message.create('error', `请输入正确的手机号`);
      return false
    }
    const params = {
      adminName:this.adminName,
      account:this.account,
      authType:this.authType,
      adminAuthType:this.adminAuthType,
      pwd:this.pwd
    }
    return this.adminListHttpService.addPost(params, this.defaultHttpConfig).subscribe((res) => {
    })

    // return
      // console.log(this.submitData(params),'zh this.submitData(params)')
  }

  submitData(data:any){

  }

  submitForm(): void {
    // console.log(this.validateForm.value);
  }


}
